import type { RowType } from '#/views/system/sysDept/sysDept.data';

import { requestClient } from '#/api/request';

export namespace SysDeptTableApi {
  export type RowTypeFetchParams = RowType;
  export interface IdFetchParams {
    id: string;
  }
  export interface ListFetchParams {
    [key: string]: any;
  }
}

/**
 * 懒加载列表查询
 * : 如果pid为空则查询所有父级,反之查询子级数据
 *
 * @return 测试树列表
 */
export async function sysDeptQueryLazyListApi(
  params: SysDeptTableApi.RowTypeFetchParams,
) {
  return requestClient.get('/sys/dept/queryLazyList', { params });
}

/**
 * 列表查询
 *  :结果支持两种结构。1.平级('flat') 2.层级('layer')
 *  :需要再请求头中传入key为: model= 'flat' | 'layer'，默认 'layer'
 *
 * @return 测试树列表: 结果支持两种结构。1.平级('flat') 2.层级('layer')
 */
export async function sysDeptQueryListApi(
  params: SysDeptTableApi.ListFetchParams,
) {
  return requestClient.get('/sys/dept/queryList', { params });
}

/**
 * 通过ID查询
 * @param params
 */
export async function sysDeptQueryByIdApi(
  params: SysDeptTableApi.IdFetchParams,
) {
  return requestClient.get('/sys/dept/queryById', { params });
}

/**
 * 新增
 */
export async function sysDeptAddApi(
  params: SysDeptTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/sys/dept/add', params);
}

/**
 * 编辑
 */
export async function sysDeptEditApi(
  params: SysDeptTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/sys/dept/edit', params);
}

/**
 * 删除
 * @param id 主键
 */
export async function sysDeptDelApi(id) {
  return requestClient.delete<boolean>(`/sys/dept/delete/${id}`);
}
